﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace mbhxnaengine.Code.GameObject
{
    class GOStone : GameObject
    {
        // The sprite used to render this game object
        //
        private GOSprite mVisual;

        // A look up table for the color a cell should be.
        //
        private Color[] mColourLookup;

        // An index to use in the colour look up table.
        //
        private int mColourIndex;

        // The cell which this piece appears on top of.
        //
        private GOCell mCell;

        // Constructor
        //
        public GOStone()
        {
            // For now, every cell has the same sprite.
            mVisual = new GOSprite();
            mVisual.LoadContent("Sprites\\circle");

            // To reprsent cell states we will change the texture colour.  We use
            // this array to determine what colour to use.
            mColourLookup = new Color[]
            {
                Color.White,
                Color.Yellow,
                Color.Orange,
                Color.Red,
                Color.Violet,
                Color.Blue,
                Color.Green,
                Color.White,
                Color.LightSlateGray
            };

            mColourIndex = 8;
        }

        // Called once, when the object is loaded.
        //
        public override void LoadContent(String fileName)
        {
        }

        // Called every frame.
        //
        public override void Update(GameTime gameTime)
        {
            mVisual.pPosition = this.pPosition;
            mVisual.pScale = this.pScale;
            mVisual.pRotation = this.pRotation;

            mVisual.pColour = mColourLookup[mColourIndex];
        }

        // Called at the end of every frame.
        //
        public override void Render(SpriteBatch batch)
        {
            mVisual.Render(batch);
        }

        //
        //
        public GOCell pContainingCell
        {
            get
            {
                return mCell;
            }
            set
            {
                mCell = value;

                // This object should appear at the same position as the cell containg it.
                this.pPosition = value.pPosition;

                // We use the same sprite as the cell, so we need to appear slightly smaller
                // so that the cell is still visible.
                this.pScale = value.pScale * 0.75f;

                // To create a bit of a visual change between the pieces and the board, we just
                // rotate the stones 180 degrees.
                this.pRotation = value.pRotation + 180.0f;
            }
        }
    }
}
